﻿
using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Collections.Generic;
using System.Xml;

namespace SimpleService.Config
{
    class ConfigUtility
    {
        /// <summary>
        /// 取得路徑
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public static string GetPath(string strPath)
        {   
            //web用
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MapPath(strPath);
            }
            else
            { //非web用
                strPath = strPath.Replace("/", "\\");
                if (strPath.StartsWith("\\"))
                {
                    strPath = strPath.TrimStart('\\');
                }
                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }

        /// <summary>
        /// 產生目錄
        /// </summary>
        /// <param name="strPath"></param>
        public static void CreateDirectory(string strPath)
        {
            string path = GetPath(strPath);
            if ( !Directory.Exists(path) )
            {
                System.IO.Directory.CreateDirectory(path);
            }
        }


    }
}
